<template>
	<view style="width: 100%;">
		<view class="answer-score-text">答题分数为</view>
		<view class="answer-score">{{ score }}</view>
		<view :class="[results=='培训通过'?'results-pass':'results-err']">{{ results }}</view>
		<view class="err-answer" v-if="Results">
			<view class="err-answer-title">以下是答错题目：</view>
			<view v-for="(item,index) in wronglist">
				<view class="err-answer-text">{{ index+1 }}：{{item.question}}</view>
				<view class="err-answer-answer">正确答案是：{{item.options[item.answer].tik == 0 ?'A':''}}{{item.options[item.answer].tik == 1 ?'B':''}}{{item.options[item.answer].tik == 2 ?'C':''}}{{item.options[item.answer].tik == 3 ?'D':''}}:{{item.options[item.answer].name}}</view>
			</view>
		</view>
		<!-- #ifdef H5 -->
		<view class="uni-btn-v" v-if="!this.Results"><button form-type="submit" class="submit" @click="register">确定</button></view>
		<view class="uni-btn-v" v-if="this.Results"><button form-type="submit" class="res-submit" @click="resRegister">重新答题</button></view>
	<!-- #endif -->
	<backnext></backnext>
	<!-- 底部导航 -->
	<footernav pagePath='user'></footernav>
	<!-- 加载动画 -->
	<loading v-if="!isloading()"></loading>
	</view>
</template>

<script>
	import {questiontrain} from '@/common/api/topics.js'
export default {
	data() {
		return { 
			score: 0, 
			results: '', /*培训通过*/
			skin: '', 
			n: 1, 
			Results: false,
			wronglist:[],
			companyid:"",
			showtype:'',
			meeting_code:'',
			userinfo:[],
			appointmentid:'',
			showclick:true,
			};
	},
	onLoad(event) {
		uni.getStorage({
			key: 'userinfo',
			success: res => {
				this.userinfo = res.data
			}
		});
		if(event){
			this.score = event.score
			this.companyid=event.companyid;
			this.showtype=event.type;
			this.results = event.results == 0?'培训通过':'培训未通过'
			this.wronglist = JSON.parse(event.wronglist)
			
			if(event.meeting_code){
				this.meeting_code=event.meeting_code
			}
			if(event.appointmentid){
				this.appointmentid=event.appointmentid
			}
			
			if(this.wronglist.length!=0){
				
			}
			this.addclass()
		}
		
	},
	methods: {
		addclass() {
			var arr = ['results-pass', 'results-err'];
			if (this.results == '培训通过') {
				this.Results = false;
				return 'results-pass';
			} else {
				// debugger
				this.Results = true;
				return 'results-err';
			}
		},
		register(){
			let that=this;
			
			uni.showToast({
			    title: '即将跳转,请稍等',
			    duration: 2000,
				icon:'none'
			});
			if(this.showclick){
				this.showclick=false;
			setTimeout(function(){
				if(that.meeting_code){
					uni.reLaunch({
					    url: '../yaoqing/InviteQrCode?meeting_code='+that.meeting_code+'&choosetype='+that.showtype
					});
				}else{
					if(that.showtype=='yq'){
						uni.reLaunch({
							url: '/pages/myyuyue/myyuyue?type=2'
						});		
					}else if(that.showtype=='yy'){
						uni.reLaunch({
							url: '/pages/myyuyue/myyuyue?type=1'
						});		
					}else{
						uni.reLaunch({
							url: '/pages/myyuyue/myyuyue?type=2'
						});
					}
				}
				
				this.showclick=true;
			},3000)
			console.log(1)
			}
			return
		},
		resRegister(){
			// uni.reLaunch({
			// 	url: '/pages/subject/problem'
			// });
					
			
			let details = {
				companyid:this.companyid,
				appointmentid:this.appointmentid,
				meeting_code:this.meeting_code,
				type:this.showtype,						
			}
			uni.reLaunch({
				// url: "/pages/myyuyue/myyuyue"
				url:"/pages/subject/problem?details="+encodeURIComponent(JSON.stringify(details))
			});
			
			console.log(1)
			return
		}
	}
};
</script>

<style>
.answer-score-text {
	color: rgba(80, 80, 80, 1);
	font-size: 14px;
	text-align: center;
	margin: 20% 0 0 0;
}
.answer-score {
	color: rgba(80, 80, 80, 1);
	font-size: 38px;
	text-align: center;
	font-weight: bold;
}
.results-pass {
	color: rgba(42, 130, 228, 1);
	font-size: 16px;
	margin: auto;
	text-align: center;
}
.results-err {
	color: rgba(212, 48, 48, 1);
	font-size: 16px;
	margin: auto;
	text-align: center;
}
.err-answer {
	margin: 10px 0 10px 10px;
}
.err-answer-title .err-answer-text {
	color: rgba(80, 80, 80, 1);
	font-size: 15px;
}
.err-answer-answer {
	color: rgba(212, 48, 48, 1);
	font-size: 14px;
}
.submit{
	color: rgba(255, 255, 255, 1);
		background-color: rgba(42, 130, 228, 1);
		border-radius: 18px;
		font-size: 15px;
		margin: auto;
		text-align: center;
		width: 192px;
		margin-top: 100px;
}
.res-submit{
	width: 192px;
		
		color: rgba(255, 255, 255, 1);
		background-color: rgba(212, 48, 48, 1);
		border-radius: 18px;
		font-size: 15px;
		text-align: center;
		width: 192px;
		margin-top: 100px;
		margin: auto;
}
</style>
